#!/usr/env/php
<?php
/**
 * only run a controller.
 */

use Inhere\Console\Application;
use Inhere\Console\Examples\Controller\HomeController;
use Inhere\Console\IO\Input;
use Toolkit\Cli\Color;

define('BASE_PATH', dirname(__DIR__));

require dirname(__DIR__) . '/test/bootstrap.php';

try {
    $input = new Input();
    $app   = new Application([
        'debug'    => true,
        'rootPath' => BASE_PATH,
    ], $input);

    $app->controller('home', HomeController::class);

    $subCmd = $input->getCommand();
    $result = $app->dispatch('home:' . $subCmd, []);

    exit((int)$result);
} catch (Exception $e) {
    $message = Color::apply('error', $e->getMessage());

    echo sprintf("%s\nFile %s:%d\nTrace:\n%s\n",
        $message, $e->getFile(), $e->getLine(), $e->getTraceAsString()
    );
}

// can also: see './alone' file
